package com.leezt.designpattern.creation.s01singleton;

import java.util.concurrent.atomic.AtomicLong;

/*
 * implement ID generator with inner static class way. This way could also be lazy load.
 */
public class InnerStaticClassIdGenerator {
    private final AtomicLong id = new AtomicLong(0);

    private InnerStaticClassIdGenerator(){}

    private static class SingletonHolder {
        private static final InnerStaticClassIdGenerator instance = new InnerStaticClassIdGenerator();
    }

    public static InnerStaticClassIdGenerator getInstance() {
        return SingletonHolder.instance;
    }

    public long getId() {
        return id.incrementAndGet();
    }
}
